package view;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;

import model.Ball;
import model.Common;
import model.PlayGround;
import model.Racket;

public class Window extends JPanel implements Runnable, Common {

	private JFrame jframe;
	private PlayGround playGround;
	private Thread animator;

	public Window() {

		initialize();
		animator = new Thread(this);
		animator.start();
		setDoubleBuffered(true);

	}

	private void initialize() {
		int width = COMMON_SCREENWIDTH;
		int height = COMMON_SCREENHEIGHT;
		this.playGround = new PlayGround(width, height);

		this.jframe = new JFrame("Teh FRAME");
		this.jframe.setResizable(false);
		this.setBackground(Color.BLACK);
		this.jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.jframe.setSize(width, height);
		this.jframe.add(this.playGround);
		this.jframe.add(this);
		this.jframe.setLocationRelativeTo(null);
		this.jframe.setVisible(true);
	}

	@Override
	public void paint(Graphics g) {
		super.paint(g);
		this.playGround.paint(g);
	}

	@Override
	public void run() {
		while (true) {
			try {
				Thread.sleep(10);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
			repaint();
			this.playGround.actBall();
		}
	}

	public static void main(String[] args) {
		new Window();
	}

}
